package com.wnxy.sddfp.payback.controller;


import com.wnxy.sddfp.common.model.dto.payback.PayBackDTO;
import com.wnxy.sddfp.common.result.Result;
import com.wnxy.sddfp.payback.service.IBorrowerPayPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 借款人还款计划 前端控制器
 */
@RestController
@RequestMapping("/pay-plan")
@Api(tags = "还款计划")
public class BorrowerPayPlanController {

    private final IBorrowerPayPlanService borrowerPayPlanService;

    // 依赖注入之通过构造器注入，在spring官网描述中更推荐这种方式。优于@Autowired注入
    public BorrowerPayPlanController(IBorrowerPayPlanService borrowerPayPlanService){
        this.borrowerPayPlanService = borrowerPayPlanService;
    }

    @ApiOperation("生成还款计划")
    @PostMapping("/inner/start")
    public Result payPlan(@RequestBody PayBackDTO payBackDTO){
        String result = borrowerPayPlanService.payPlan(payBackDTO);
        return Result.ok(result);
    }

    @ApiOperation("用户还款")
    @GetMapping("/repay/date")
    public Result doRepay(String date) {
        borrowerPayPlanService.doRepay(date);
        return Result.ok("还款成功");
    }
}

